import request from '@/utils/request'
/**
 *  发送验证码
 * @param {*} mobile 手机号
 * @returns promise
 */
export const sendCode = mobile => {
  return request({
    url: '/v1_0/sms/codes/' + mobile
  })
}

/**
 * 登录接口
 * @param {*} data { mobile code}
 * @returns promise
 */
export const login = (data) => {
  return request({
    url: '/v1_0/authorizations',
    method: 'POST',
    data
  })
}

/**
 * 获取用户自己的信息
 * @returns pormise
 */
export const getUserInfo = () => {
  return request({
    url: '/v1_0/user'
  })
}

/**
 * 获取标签信息
 * @returns promise
 */
export const getUserChannels = () => {
  return request({
    url: '/v1_0/user/channels'
  })
}

/**
 * 关注
 * @param {*} target 用户ID
 * @returns
 */
export const addUserFollow = target => {
  return request({
    url: '/v1_0/user/followings',
    method: 'POST',
    data: {
      target
    }
  })
}

/**
 * 取关
 * @param {*} target
 * @returns
 */
export const deleteUserFollow = target => {
  return request({
    url: '/v1_0/user/followings/' + target,
    method: 'DELETE'
  })
}

/**
 * 获取用户信息
 * @returns
 */
export const getUserProfile = () => {
  return request({
    url: '/v1_0/user/profile'
  })
}

/**
 * 更新资料
 * @returns {*} data { name? photo? birthday? gender }
 */
export const updateUserProfile = data => {
  return request({
    url: '/v1_0/user/profile',
    method: 'PATCH',
    data
  })
}

/**
 * 更新头像
 * @param {*} data formdata
 * @returns
 */
export const updateUserAvatar = data => {
  return request({
    url: '/v1_0/user/photo',
    method: 'PATCH',
    data
  })
}
